package dnl.toolbox.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;

public class Classes {

	/**
	 * Returns <code>true</code> only if class c is a non abstract class that
	 * is public and has a public empty constructor.
	 * 
	 * @param c
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static boolean hasPublicEmptyConstructor(Class<?> c) {
		Constructor<?> constructor = null;
		try {
			constructor = c.getConstructor((Class) null);
		} catch (NoSuchMethodException noConstructor) {
			return false;
		}
		boolean classIsPublic = Modifier.isPublic(c.getModifiers());
		boolean classIsAbstract = Modifier.isAbstract(c.getModifiers());
		boolean constructorIsPublic = constructor != null
				&& Modifier.isPublic(constructor.getModifiers());
		return classIsPublic && !classIsAbstract && constructorIsPublic;
	}
}
